package cn.zxf.note.note.note;

import org.springframework.data.jpa.repository.Query;

import cn.zxf.note.common.jpa.EntityRepository;
import org.springframework.data.repository.query.Param;

/**
 * Created by zengxf on 2019/3/27.
 */
public interface NoteRepository extends EntityRepository<Note> {

    default int countByTypeId(Integer typeId) {
        return this.countByTypeIdAndStatus(typeId, NoteStatusEnum.NORMAL.code);
    }

    @Query("SELECT COUNT(*) FROM Note WHERE status = :status AND typeId = :type_id")
    int countByTypeIdAndStatus(
            @Param("type_id") Integer typeId,
            @Param("status") Integer status
    );

}
